import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

import {resolve} from 'path'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { name, version, engines, dependencies, devDependencies } from "./package.json";

const __APP_INFO__ = {
  pkg: { name, version, engines, dependencies, devDependencies },
  buildTimestamp: Date.now(),
};

const pathSrc = resolve(__dirname, 'src')

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  
  console.log(env)

  return {
    base: env.VITE_BASE_URL || '/',
    build: {
      outDir: 'dist',
      // assetsDir: 'static'
    },
    server: {
      host: '127.0.0.1',
      port: 51730,
      proxy: {
        '/api': {
          target: 'http://localhost:4996',
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/api/, '')
        }
      },
      
    },
    
    plugins: [vue()
      ,AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      })
    ],
  
    resolve: {
      alias: {
        '@': pathSrc
      }
    },
  
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "@/styles/element/index.scss" as *;`
        }
      }
    },
    define: {
      __APP_INFO__: JSON.stringify(__APP_INFO__)
    }
  }
})
